#include "cmodel.h"

/**
 * CModel - default constructor
 */
CModel::CModel() {}
//---------------------------------------------------------------------------

/**
 * ~CModel() - default destructor
 */
CModel::~CModel() {}
//---------------------------------------------------------------------------

/**
 * addNewMesh - adds new empty mesh
 * @return pointer on new mesh
 */
CMesh* CModel::addNewMesh() {
  meshes.push_back(new CMesh());
  return meshes[meshes.size() - 1];
}
//---------------------------------------------------------------------------

/**
 * addNewMaterial - adds new empty material
 * @return pointer on new material
 */
CMaterial* CModel::addNewMaterial() {
  materials.push_back(new CMaterial());
  return materials[materials.size() - 1];
}
//---------------------------------------------------------------------------

/**
 * getNumOfMeshes - returns num of meshes in model
 * @return num of meshes
 */
int CModel::getNumOfMeshes() const {
  return meshes.size();
}
//---------------------------------------------------------------------------

/**
 * getNumOfMaterials - returns num of materials in model
 * @return num of materials
 */
int CModel::getNumOfMaterials() const {
  return materials.size();
}
//---------------------------------------------------------------------------

/**
 * getMeshPtr - returns pointer on given mesh
 * @param index
 * @return mesh on position "index"
 */
CMesh* CModel::getMeshPtr(int index) const {

  // TODO: meze
  return meshes[index];
}
//---------------------------------------------------------------------------

/**
 * getMaterialPtr - returns pointer on given material
 * @param index
 * @return material on position "index"
 */
CMaterial* CModel::getMaterialPtr(int index) const {
  return materials[index];
}
//---------------------------------------------------------------------------

/**
 * free - deletes model from memory
 */
void CModel::free() {

  // Free all meshes
  for(vector<CMesh*>::iterator i = meshes.begin(); i < meshes.end(); i++) {
    if (*i) delete *i;
  }

  // Free all materials
  for(vector<CMaterial*>::iterator i = materials.begin(); i < materials.end();
      i++) {
    if (*i) delete *i;
  }

  meshes.clear();
  materials.clear();
}
//---------------------------------------------------------------------------
